package com.order.controller;

import com.order.bean.Order;
import com.order.service.OrderService;
import com.order.util.CommonResult;
import com.order.util.RestSupport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 模拟高并发扣减库存接口
 *
 * @author roseonly
 */
@RestController
@Slf4j
public class OrderController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private OrderService orderService;

    @Autowired
    private RestSupport restSupport;

    @PostMapping("/order")
    public CommonResult order(@RequestBody Order order) {
        return restSupport.get(() -> orderService.order(order) + "");
    }

    @GetMapping("/get")
    public CommonResult get(@RequestParam("id") Integer id) {
        return restSupport.get(() -> orderService.get(id));
    }

    @GetMapping("/getList")
    public CommonResult getList() {
        return restSupport.get(() -> orderService.getList());
    }

    @GetMapping("/getPort")
    public String getEnvironment() {
        return port;
    }

}
